package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.InstitutionTypeAddDTO;
import org.jsola.hr.dto.InstitutionTypeUpdateDTO;
import org.jsola.hr.entity.InstitutionTypeDO;
import org.jsola.hr.query.InstitutionTypeQuery;
import org.jsola.hr.service.IInstitutionTypeService;
import org.jsola.hr.vo.InstitutionTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 制度分类
 *
 * @author zhr
 */
@Component
public class InstitutionTypeTestHelper extends BaseTestHelper {
    
    @Autowired
    private IInstitutionTypeService institutionTypeService;

    /**
     * 生成add测试数据
     * @return InstitutionTypeAddDTO
     */
    public InstitutionTypeAddDTO getInstitutionTypeAddDTO(){
        InstitutionTypeAddDTO institutionTypeAddDTO = new InstitutionTypeAddDTO();
        institutionTypeAddDTO.setInstitutionTypeName(getRandomValue("varchar",32));
        institutionTypeAddDTO.setInstitutionTypeIntroduce(getRandomValue("varchar",64));
        institutionTypeAddDTO.setParentId(getRandomValue("varchar",32));
        institutionTypeAddDTO.setSort(SafeKit.getLong(getRandomValue("bigint",10)));
        institutionTypeAddDTO.setLevel(SafeKit.getInteger(getRandomValue("int",10)));
        return institutionTypeAddDTO;
    }


    /**
     * 生成update测试数据
     * @return InstitutionTypeUpdateDTO
     */
    public InstitutionTypeUpdateDTO getInstitutionTypeUpdateDTO(InstitutionTypeVO institutionTypeVO){
        return institutionTypeService.selectDOById(institutionTypeVO.getId(), SITE_ID).to(InstitutionTypeUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return InstitutionTypeQuery
     */
    public InstitutionTypeQuery getInstitutionTypeQuery() {
        InstitutionTypeQuery institutionTypeQuery = new InstitutionTypeQuery();
        List<InstitutionTypeDO> institutionTypeDOList = institutionTypeService.list(new InstitutionTypeDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(institutionTypeDOList)) {
            InstitutionTypeDO institutionTypeDO = institutionTypeDOList.get(0);
            institutionTypeQuery = institutionTypeDO.to(InstitutionTypeQuery.class);
        }
        return institutionTypeQuery;
    }

    /**
     * 保存示例
     * @return InstitutionTypeVO
     */
    public InstitutionTypeVO saveInstitutionTypeExample(){
        InstitutionTypeAddDTO addDTO = this.getInstitutionTypeAddDTO();
        InstitutionTypeVO institutionTypeVO = institutionTypeService.save(addDTO,buildTokenUser());
        return institutionTypeVO;
    }


}

